#pragma once

#include <mutex>
using std::mutex;
using std::lock_guard;

template<class T>
class CSingleton
{
private:
	static mutex _mutex;
	static T* _instance;
public:
	static T* I() { 
		if (_instance == nullptr)
		{
			lock_guard<mutex> guard(_mutex);
			if (_instance == nullptr)
			{
				_instance = new T();
			}
		}
		return _instance;
	}
};

template<class T>
mutex CSingleton<T>::_mutex;

template<class T>
T* CSingleton<T>::_instance = NULL;